﻿#region Using directives

using System;
using System.Data;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;

using dmoz.Entities;
using dmoz.Data;

#endregion

namespace dmoz.Data.Bases
{	
	///<summary>
	/// This class is the base class for any <see cref="ResourcePerCategoryProviderBase"/> implementation.
	/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
	///</summary>
	public abstract partial class ResourcePerCategoryProviderBaseCore : EntityProviderBase<dmoz.Entities.ResourcePerCategory, dmoz.Entities.ResourcePerCategoryKey>
	{		
		#region Get from Many To Many Relationship Functions
		#endregion	
		
		#region Delete Methods

		/// <summary>
		/// 	Deletes a row from the DataSource.
		/// </summary>
		/// <param name="transactionManager">A <see cref="TransactionManager"/> object.</param>
		/// <param name="key">The unique identifier of the row to delete.</param>
		/// <returns>Returns true if operation suceeded.</returns>
		public override bool Delete(TransactionManager transactionManager, dmoz.Entities.ResourcePerCategoryKey key)
		{
			return Delete(transactionManager, key.IdCategory, key.IdResource);
		}
		
		/// <summary>
		/// 	Deletes a row from the DataSource.
		/// </summary>
		/// <param name="idCategory">. Primary Key.</param>
		/// <param name="idResource">. Primary Key.</param>
		/// <remarks>Deletes based on primary key(s).</remarks>
		/// <returns>Returns true if operation suceeded.</returns>
		public bool Delete(System.Int32 idCategory, System.Int32 idResource)
		{
			return Delete(null, idCategory, idResource);
		}
		
		/// <summary>
		/// 	Deletes a row from the DataSource.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="idCategory">. Primary Key.</param>
		/// <param name="idResource">. Primary Key.</param>
		/// <remarks>Deletes based on primary key(s).</remarks>
		/// <returns>Returns true if operation suceeded.</returns>
		public abstract bool Delete(TransactionManager transactionManager, System.Int32 idCategory, System.Int32 idResource);		
		
		#endregion Delete Methods
		
		#region Get By Foreign Key Functions
	
		/// <summary>
		/// 	Gets rows from the datasource based on the Category_ResourcePerCategory_FK1 key.
		///		Category_ResourcePerCategory_FK1 Description: 
		/// </summary>
		/// <param name="idCategory"></param>
		/// <returns>Returns a typed collection of dmoz.Entities.ResourcePerCategory objects.</returns>
		public dmoz.Entities.TList<ResourcePerCategory> GetByIdCategory(System.Int32 idCategory)
		{
			int count = -1;
			return GetByIdCategory(idCategory, 0,int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the Category_ResourcePerCategory_FK1 key.
		///		Category_ResourcePerCategory_FK1 Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="idCategory"></param>
		/// <returns>Returns a typed collection of dmoz.Entities.ResourcePerCategory objects.</returns>
		/// <remarks></remarks>
		public dmoz.Entities.TList<ResourcePerCategory> GetByIdCategory(TransactionManager transactionManager, System.Int32 idCategory)
		{
			int count = -1;
			return GetByIdCategory(transactionManager, idCategory, 0, int.MaxValue, out count);
		}
		
			/// <summary>
		/// 	Gets rows from the datasource based on the Category_ResourcePerCategory_FK1 key.
		///		Category_ResourcePerCategory_FK1 Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="idCategory"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		///  <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of dmoz.Entities.ResourcePerCategory objects.</returns>
		public dmoz.Entities.TList<ResourcePerCategory> GetByIdCategory(TransactionManager transactionManager, System.Int32 idCategory, int start, int pageLength)
		{
			int count = -1;
			return GetByIdCategory(transactionManager, idCategory, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the Category_ResourcePerCategory_FK1 key.
		///		categoryResourcePerCategoryFk1 Description: 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="idCategory"></param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of dmoz.Entities.ResourcePerCategory objects.</returns>
		public dmoz.Entities.TList<ResourcePerCategory> GetByIdCategory(System.Int32 idCategory, int start, int pageLength)
		{
			int count =  -1;
			return GetByIdCategory(null, idCategory, start, pageLength,out count);	
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the Category_ResourcePerCategory_FK1 key.
		///		categoryResourcePerCategoryFk1 Description: 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="idCategory"></param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of dmoz.Entities.ResourcePerCategory objects.</returns>
		public dmoz.Entities.TList<ResourcePerCategory> GetByIdCategory(System.Int32 idCategory, int start, int pageLength,out int count)
		{
			return GetByIdCategory(null, idCategory, start, pageLength, out count);	
		}
						
		/// <summary>
		/// 	Gets rows from the datasource based on the Category_ResourcePerCategory_FK1 key.
		///		Category_ResourcePerCategory_FK1 Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="idCategory"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">The total number of records.</param>
		/// <returns>Returns a typed collection of dmoz.Entities.ResourcePerCategory objects.</returns>
		public abstract dmoz.Entities.TList<ResourcePerCategory> GetByIdCategory(TransactionManager transactionManager, System.Int32 idCategory, int start, int pageLength, out int count);
		
	
		/// <summary>
		/// 	Gets rows from the datasource based on the Resource_ResourcePerCategory_FK1 key.
		///		Resource_ResourcePerCategory_FK1 Description: 
		/// </summary>
		/// <param name="idResource"></param>
		/// <returns>Returns a typed collection of dmoz.Entities.ResourcePerCategory objects.</returns>
		public dmoz.Entities.TList<ResourcePerCategory> GetByIdResource(System.Int32 idResource)
		{
			int count = -1;
			return GetByIdResource(idResource, 0,int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the Resource_ResourcePerCategory_FK1 key.
		///		Resource_ResourcePerCategory_FK1 Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="idResource"></param>
		/// <returns>Returns a typed collection of dmoz.Entities.ResourcePerCategory objects.</returns>
		/// <remarks></remarks>
		public dmoz.Entities.TList<ResourcePerCategory> GetByIdResource(TransactionManager transactionManager, System.Int32 idResource)
		{
			int count = -1;
			return GetByIdResource(transactionManager, idResource, 0, int.MaxValue, out count);
		}
		
			/// <summary>
		/// 	Gets rows from the datasource based on the Resource_ResourcePerCategory_FK1 key.
		///		Resource_ResourcePerCategory_FK1 Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="idResource"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		///  <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of dmoz.Entities.ResourcePerCategory objects.</returns>
		public dmoz.Entities.TList<ResourcePerCategory> GetByIdResource(TransactionManager transactionManager, System.Int32 idResource, int start, int pageLength)
		{
			int count = -1;
			return GetByIdResource(transactionManager, idResource, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the Resource_ResourcePerCategory_FK1 key.
		///		resourceResourcePerCategoryFk1 Description: 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="idResource"></param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of dmoz.Entities.ResourcePerCategory objects.</returns>
		public dmoz.Entities.TList<ResourcePerCategory> GetByIdResource(System.Int32 idResource, int start, int pageLength)
		{
			int count =  -1;
			return GetByIdResource(null, idResource, start, pageLength,out count);	
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the Resource_ResourcePerCategory_FK1 key.
		///		resourceResourcePerCategoryFk1 Description: 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="idResource"></param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of dmoz.Entities.ResourcePerCategory objects.</returns>
		public dmoz.Entities.TList<ResourcePerCategory> GetByIdResource(System.Int32 idResource, int start, int pageLength,out int count)
		{
			return GetByIdResource(null, idResource, start, pageLength, out count);	
		}
						
		/// <summary>
		/// 	Gets rows from the datasource based on the Resource_ResourcePerCategory_FK1 key.
		///		Resource_ResourcePerCategory_FK1 Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="idResource"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">The total number of records.</param>
		/// <returns>Returns a typed collection of dmoz.Entities.ResourcePerCategory objects.</returns>
		public abstract dmoz.Entities.TList<ResourcePerCategory> GetByIdResource(TransactionManager transactionManager, System.Int32 idResource, int start, int pageLength, out int count);
		
		#endregion

		#region Get By Index Functions
		
		/// <summary>
		/// 	Gets a row from the DataSource based on its primary key.
		/// </summary>
		/// <param name="transactionManager">A <see cref="TransactionManager"/> object.</param>
		/// <param name="key">The unique identifier of the row to retrieve.</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <returns>Returns an instance of the Entity class.</returns>
		public override dmoz.Entities.ResourcePerCategory Get(TransactionManager transactionManager, dmoz.Entities.ResourcePerCategoryKey key, int start, int pageLength)
		{
			return GetByIdCategoryIdResource(transactionManager, key.IdCategory, key.IdResource, start, pageLength);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the primary key ResourcePerCategory_PK index.
		/// </summary>
		/// <param name="idCategory"></param>
		/// <param name="idResource"></param>
		/// <returns>Returns an instance of the <see cref="dmoz.Entities.ResourcePerCategory"/> class.</returns>
		public dmoz.Entities.ResourcePerCategory GetByIdCategoryIdResource(System.Int32 idCategory, System.Int32 idResource)
		{
			int count = -1;
			return GetByIdCategoryIdResource(null,idCategory, idResource, 0, int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the ResourcePerCategory_PK index.
		/// </summary>
		/// <param name="idCategory"></param>
		/// <param name="idResource"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="dmoz.Entities.ResourcePerCategory"/> class.</returns>
		public dmoz.Entities.ResourcePerCategory GetByIdCategoryIdResource(System.Int32 idCategory, System.Int32 idResource, int start, int pageLength)
		{
			int count = -1;
			return GetByIdCategoryIdResource(null, idCategory, idResource, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the ResourcePerCategory_PK index.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="idCategory"></param>
		/// <param name="idResource"></param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="dmoz.Entities.ResourcePerCategory"/> class.</returns>
		public dmoz.Entities.ResourcePerCategory GetByIdCategoryIdResource(TransactionManager transactionManager, System.Int32 idCategory, System.Int32 idResource)
		{
			int count = -1;
			return GetByIdCategoryIdResource(transactionManager, idCategory, idResource, 0, int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the ResourcePerCategory_PK index.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="idCategory"></param>
		/// <param name="idResource"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="dmoz.Entities.ResourcePerCategory"/> class.</returns>
		public dmoz.Entities.ResourcePerCategory GetByIdCategoryIdResource(TransactionManager transactionManager, System.Int32 idCategory, System.Int32 idResource, int start, int pageLength)
		{
			int count = -1;
			return GetByIdCategoryIdResource(transactionManager, idCategory, idResource, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the ResourcePerCategory_PK index.
		/// </summary>
		/// <param name="idCategory"></param>
		/// <param name="idResource"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="dmoz.Entities.ResourcePerCategory"/> class.</returns>
		public dmoz.Entities.ResourcePerCategory GetByIdCategoryIdResource(System.Int32 idCategory, System.Int32 idResource, int start, int pageLength, out int count)
		{
			return GetByIdCategoryIdResource(null, idCategory, idResource, start, pageLength, out count);
		}
		
				
		/// <summary>
		/// 	Gets rows from the datasource based on the ResourcePerCategory_PK index.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="idCategory"></param>
		/// <param name="idResource"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">The total number of records.</param>
		/// <returns>Returns an instance of the <see cref="dmoz.Entities.ResourcePerCategory"/> class.</returns>
		public abstract dmoz.Entities.ResourcePerCategory GetByIdCategoryIdResource(TransactionManager transactionManager, System.Int32 idCategory, System.Int32 idResource, int start, int pageLength, out int count);
						
		#endregion "Get By Index Functions"
	
		#region Custom Methods
		
		
		#endregion

		#region Helper Functions	
		
		/// <summary>
		/// Fill a dmoz.Entities.TList&lt;ResourcePerCategory&gt; From a DataReader.
		/// </summary>
		/// <param name="reader">Datareader</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">number of rows.</param>
		/// <returns>a <see cref="dmoz.Entities.TList&lt;ResourcePerCategory&gt;"/></returns>
		public static dmoz.Entities.TList<ResourcePerCategory> Fill(IDataReader reader, dmoz.Entities.TList<ResourcePerCategory> rows, int start, int pageLength)
		{
		// advance to the starting row
		for (int i = 0; i < start; i++)
		{
			if (!reader.Read())
			return rows; // not enough rows, just return
		}
		for (int i = 0; i < pageLength; i++)
		{
			if (!reader.Read())
			break; // we are done
			string key = null;
			
			dmoz.Entities.ResourcePerCategory c = null;
			if (DataRepository.Provider.UseEntityFactory)
			{
			key = new System.Text.StringBuilder("ResourcePerCategory")
			.Append("|").Append((reader.IsDBNull(((int)dmoz.Entities.ResourcePerCategoryColumn.IdCategory - 1))?(int)0:(System.Int32)reader[((int)dmoz.Entities.ResourcePerCategoryColumn.IdCategory - 1)]).ToString())
			.Append("|").Append((reader.IsDBNull(((int)dmoz.Entities.ResourcePerCategoryColumn.IdResource - 1))?(int)0:(System.Int32)reader[((int)dmoz.Entities.ResourcePerCategoryColumn.IdResource - 1)]).ToString()).ToString();
			c = EntityManager.LocateOrCreate<ResourcePerCategory>(
			key.ToString(), // EntityTrackingKey
			"ResourcePerCategory",  //Creational Type
			DataRepository.Provider.EntityCreationalFactoryType,  //Factory used to create entity
			DataRepository.Provider.EnableEntityTracking); // Track this entity?
			}
			else
			{
			c = new dmoz.Entities.ResourcePerCategory();
			}
			
			if (!DataRepository.Provider.EnableEntityTracking ||
			c.EntityState == EntityState.Added ||
			(DataRepository.Provider.EnableEntityTracking &&
			((DataRepository.Provider.CurrentLoadPolicy == LoadPolicy.PreserveChanges && c.EntityState == EntityState.Unchanged) ||
			(DataRepository.Provider.CurrentLoadPolicy == LoadPolicy.DiscardChanges && (c.EntityState == EntityState.Unchanged ||
								c.EntityState == EntityState.Changed)))))
						{
			c.SuppressEntityEvents = true;
			c.IdCategory = (System.Int32)reader["idCategory"];
			c.OriginalIdCategory = c.IdCategory;
			c.IdResource = (System.Int32)reader["idResource"];
			c.OriginalIdResource = c.IdResource;
			c.EntityTrackingKey = key;
			c.AcceptChanges();
			c.SuppressEntityEvents = false;
			}
			rows.Add(c);
		}
		return rows;
		}		
		/// <summary>
		/// Refreshes the <see cref="dmoz.Entities.ResourcePerCategory"/> object from the <see cref="IDataReader"/>.
		/// </summary>
		/// <param name="reader">The <see cref="IDataReader"/> to read from.</param>
		/// <param name="entity">The <see cref="dmoz.Entities.ResourcePerCategory"/> object to refresh.</param>
		public static void RefreshEntity(IDataReader reader, dmoz.Entities.ResourcePerCategory entity)
		{
			if (!reader.Read()) return;
			
			entity.IdCategory = (System.Int32)reader["idCategory"];
			entity.OriginalIdCategory = (System.Int32)reader["idCategory"];
			entity.IdResource = (System.Int32)reader["idResource"];
			entity.OriginalIdResource = (System.Int32)reader["idResource"];
			entity.AcceptChanges();
		}
		
		/// <summary>
		/// Refreshes the <see cref="dmoz.Entities.ResourcePerCategory"/> object from the <see cref="DataSet"/>.
		/// </summary>
		/// <param name="dataSet">The <see cref="DataSet"/> to read from.</param>
		/// <param name="entity">The <see cref="dmoz.Entities.ResourcePerCategory"/> object.</param>
		public static void RefreshEntity(DataSet dataSet, dmoz.Entities.ResourcePerCategory entity)
		{
			DataRow dataRow = dataSet.Tables[0].Rows[0];
			
			entity.IdCategory = (System.Int32)dataRow["idCategory"];
			entity.OriginalIdCategory = (System.Int32)dataRow["idCategory"];
			entity.IdResource = (System.Int32)dataRow["idResource"];
			entity.OriginalIdResource = (System.Int32)dataRow["idResource"];
			entity.AcceptChanges();
		}
		#endregion 
		
		#region DeepLoad Methods
		/// <summary>
		/// Deep Loads the <see cref="IEntity"/> object with criteria based of the child 
		/// property collections only N Levels Deep based on the <see cref="DeepLoadType"/>.
		/// </summary>
		/// <remarks>
		/// Use this method with caution as it is possible to DeepLoad with Recursion and traverse an entire object graph.
		/// </remarks>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="entity">The <see cref="dmoz.Entities.ResourcePerCategory"/> object to load.</param>
		/// <param name="deep">Boolean. A flag that indicates whether to recursively save all Property Collection that are descendants of this instance. If True, saves the complete object graph below this object. If False, saves this object only. </param>
		/// <param name="deepLoadType">DeepLoadType Enumeration to Include/Exclude object property collections from Load.</param>
		/// <param name="childTypes">dmoz.Entities.ResourcePerCategory Property Collection Type Array To Include or Exclude from Load</param>
		/// <param name="innerList">A collection of child types for easy access.</param>
	    /// <exception cref="ArgumentNullException">entity or childTypes is null.</exception>
	    /// <exception cref="ArgumentException">deepLoadType has invalid value.</exception>
		internal override void DeepLoad(TransactionManager transactionManager, dmoz.Entities.ResourcePerCategory entity, bool deep, DeepLoadType deepLoadType, System.Type[] childTypes, DeepSession innerList)
		{
			if(entity == null)
				return;

			#region IdCategorySource	
			if (CanDeepLoad(entity, "Category|IdCategorySource", deepLoadType, innerList) 
				&& entity.IdCategorySource == null)
			{
				object[] pkItems = new object[1];
				pkItems[0] = entity.IdCategory;
				Category tmpEntity = EntityManager.LocateEntity<Category>(EntityLocator.ConstructKeyFromPkItems(typeof(Category), pkItems), DataRepository.Provider.EnableEntityTracking);
				if (tmpEntity != null)
					entity.IdCategorySource = tmpEntity;
				else
					entity.IdCategorySource = DataRepository.CategoryProvider.GetById(transactionManager, entity.IdCategory);		
				
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'IdCategorySource' loaded. key " + entity.EntityTrackingKey);
				#endif 
				
				if (deep && entity.IdCategorySource != null)
				{
					innerList.SkipChildren = true;
					DataRepository.CategoryProvider.DeepLoad(transactionManager, entity.IdCategorySource, deep, deepLoadType, childTypes, innerList);
					innerList.SkipChildren = false;
				}
					
			}
			#endregion IdCategorySource

			#region IdResourceSource	
			if (CanDeepLoad(entity, "Resource|IdResourceSource", deepLoadType, innerList) 
				&& entity.IdResourceSource == null)
			{
				object[] pkItems = new object[1];
				pkItems[0] = entity.IdResource;
				Resource tmpEntity = EntityManager.LocateEntity<Resource>(EntityLocator.ConstructKeyFromPkItems(typeof(Resource), pkItems), DataRepository.Provider.EnableEntityTracking);
				if (tmpEntity != null)
					entity.IdResourceSource = tmpEntity;
				else
					entity.IdResourceSource = DataRepository.ResourceProvider.GetById(transactionManager, entity.IdResource);		
				
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'IdResourceSource' loaded. key " + entity.EntityTrackingKey);
				#endif 
				
				if (deep && entity.IdResourceSource != null)
				{
					innerList.SkipChildren = true;
					DataRepository.ResourceProvider.DeepLoad(transactionManager, entity.IdResourceSource, deep, deepLoadType, childTypes, innerList);
					innerList.SkipChildren = false;
				}
					
			}
			#endregion IdResourceSource
			
			//used to hold DeepLoad method delegates and fire after all the local children have been loaded.
			Dictionary<string, KeyValuePair<Delegate, object>> deepHandles = new Dictionary<string, KeyValuePair<Delegate, object>>();
			
			//Fire all DeepLoad Items
			foreach(KeyValuePair<Delegate, object> pair in deepHandles.Values)
		    {
                pair.Key.DynamicInvoke((object[])pair.Value);
		    }
			deepHandles = null;
		}
		
		#endregion 
		
		#region DeepSave Methods

		/// <summary>
		/// Deep Save the entire object graph of the dmoz.Entities.ResourcePerCategory object with criteria based of the child 
		/// Type property array and DeepSaveType.
		/// </summary>
		/// <param name="transactionManager">The transaction manager.</param>
		/// <param name="entity">dmoz.Entities.ResourcePerCategory instance</param>
		/// <param name="deepSaveType">DeepSaveType Enumeration to Include/Exclude object property collections from Save.</param>
		/// <param name="childTypes">dmoz.Entities.ResourcePerCategory Property Collection Type Array To Include or Exclude from Save</param>
		/// <param name="innerList">A Hashtable of child types for easy access.</param>
		internal override bool DeepSave(TransactionManager transactionManager, dmoz.Entities.ResourcePerCategory entity, DeepSaveType deepSaveType, System.Type[] childTypes, DeepSession innerList)
		{	
			if (entity == null)
				return false;
							
			#region Composite Parent Properties
			//Save Source Composite Properties, however, don't call deep save on them.  
			//So they only get saved a single level deep.
			
			#region IdCategorySource
			if (CanDeepSave(entity, "Category|IdCategorySource", deepSaveType, innerList) 
				&& entity.IdCategorySource != null)
			{
				DataRepository.CategoryProvider.Save(transactionManager, entity.IdCategorySource);
				entity.IdCategory = entity.IdCategorySource.Id;
			}
			#endregion 
			
			#region IdResourceSource
			if (CanDeepSave(entity, "Resource|IdResourceSource", deepSaveType, innerList) 
				&& entity.IdResourceSource != null)
			{
				DataRepository.ResourceProvider.Save(transactionManager, entity.IdResourceSource);
				entity.IdResource = entity.IdResourceSource.Id;
			}
			#endregion 
			#endregion Composite Parent Properties

			// Save Root Entity through Provider
			if (!entity.IsDeleted)
				this.Save(transactionManager, entity);
			
			//used to hold DeepSave method delegates and fire after all the local children have been saved.
			Dictionary<Delegate, object> deepHandles = new Dictionary<Delegate, object>();
			//Fire all DeepSave Items
			foreach(KeyValuePair<Delegate, object> pair in deepHandles)
		    {
                pair.Key.DynamicInvoke((object[])pair.Value);
		    }
			
			// Save Root Entity through Provider, if not already saved in delete mode
			if (entity.IsDeleted)
				this.Save(transactionManager, entity);
				

			deepHandles = null;
						
			return true;
		}
		#endregion
	} // end class
	
	#region ResourcePerCategoryChildEntityTypes
	
	///<summary>
	/// Enumeration used to expose the different child entity types 
	/// for child properties in <c>dmoz.Entities.ResourcePerCategory</c>
	///</summary>
	public enum ResourcePerCategoryChildEntityTypes
	{
		
		///<summary>
		/// Composite Property for <c>Category</c> at IdCategorySource
		///</summary>
		[ChildEntityType(typeof(Category))]
		Category,
			
		///<summary>
		/// Composite Property for <c>Resource</c> at IdResourceSource
		///</summary>
		[ChildEntityType(typeof(Resource))]
		Resource,
		}
	
	#endregion ResourcePerCategoryChildEntityTypes
	
	#region ResourcePerCategoryFilterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="SqlFilterBuilder&lt;ResourcePerCategoryColumn&gt;"/> class
	/// that is used exclusively with a <see cref="ResourcePerCategory"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class ResourcePerCategoryFilterBuilder : SqlFilterBuilder<ResourcePerCategoryColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the ResourcePerCategoryFilterBuilder class.
		/// </summary>
		public ResourcePerCategoryFilterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the ResourcePerCategoryFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public ResourcePerCategoryFilterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the ResourcePerCategoryFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public ResourcePerCategoryFilterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion ResourcePerCategoryFilterBuilder
	
	#region ResourcePerCategoryParameterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="ParameterizedSqlFilterBuilder&lt;ResourcePerCategoryColumn&gt;"/> class
	/// that is used exclusively with a <see cref="ResourcePerCategory"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class ResourcePerCategoryParameterBuilder : ParameterizedSqlFilterBuilder<ResourcePerCategoryColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the ResourcePerCategoryParameterBuilder class.
		/// </summary>
		public ResourcePerCategoryParameterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the ResourcePerCategoryParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public ResourcePerCategoryParameterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the ResourcePerCategoryParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public ResourcePerCategoryParameterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion ResourcePerCategoryParameterBuilder
} // end namespace
